<?php

namespace App\Admin\Actions\ShopProduct;

use App\Library\Models\AdminShopProductModel;
use App\Models\ShopProductModel;
use Encore\Admin\Actions\Response;
use Encore\Admin\Actions\RowAction;
use Illuminate\Http\Request;

class ShopProductSortAction extends RowAction
{
    public $name = '排序';

    public function handle(AdminShopProductModel $model, Request $request): Response
    {
        $model->sort = $request->sort;
        $model->save();
        return $this->response()->success('操作成功')->refresh();
    }

    public function form(ShopProductModel $model): void
    {
        $this->text('sort', '排序')->default($model->sort)->rules('integer|min:0')->required()
            ->attribute('maxlength', 5)->attribute('onfocus', 'checkInteger(this)')
            ->attribute('onkeyup', 'checkInteger(this)');
    }
}
